<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script src="../day8//js/ajax.js"></script>
    <script>
        function reTxt(url, key) {
            return new Promise(function (resolve, reject) {
                setTimeout(function () {
                    ajax({
                        url: url,
                        success: function (txt) {
                            resolve(txt)
                        }
                    })
                }, key)


            })
        }

        var p1 = reTxt("../day8/data/1.txt", 3000)
        var p2 = reTxt("../day8/data/2.txt", 0)
        var p = Promise.race([p1, p2])
        console.log(p);
        p.then(function (txt) {
            console.log(txt);
        }).catch(function (err) {
            console.log(err);
        })
    </script>
</body>

</html>